﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>API</title>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../bootstrap/css/pub.css" rel="stylesheet" />
    <script src="../bootstrap/js/jquery.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
        <script src="bootstrap/js/html5shiv.min.js"></script>
        <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
    <script src="../config.js"></script>
    <script src="../bootstrap/js/Common.js"></script>
    <script src="../bootstrap/js/controls.js"></script>
    <script type="text/javascript">
        var selectRue = GetUrlParam("identity");
        var ruleName = decodeURI(GetUrlParam("ruleName"));
        $(function () {
            //菜单
            var menus = [
                { name: "新增", action: "openDefineWin()", css: "btn-primary" },
                { name: "返回策略列表", action: "ReturnHome()", css: "btn-primary" },
            ];
            $(".menu-container").menu({ items: menus });
            //列表
            var columns = [
                {
                    name: "报警策略", field: "rname", formatter: function (value) {
                        return ruleName;
                    }
                },
                { name: "触发器名称", field: "name" },
                { name: "触发次序", field: "index" },
                { name: "参数", field: "parameters" },
                { name: "操作类型", field: "actionType" },
                { name: "脚本", field: "actionScript" },
                {
                    name: "操作",
                    field: "index",
                    title: '操作',
                    formatter: function (value, dataRow) {
                        return '<a href="javascript:void(0);" onclick="openModifyWin(\'' + value + '\')" class="btn btn-sm btn-info" ><i class="fa fa-trash-o"></i>编辑</a>' +
                            '&nbsp&nbsp&nbsp<a href="javascript:void(0);" onclick="openDeleteWin(\'' + dataRow.index + '\',\'' + dataRow.name + '\',\'' + dataRow.testFunc + '\',' +
                            '\'' + dataRow.parameters + '\',\'' + dataRow.actionType + '\',\'' + dataRow.actionScript + '\')" class="btn btn-sm btn-info" ><i class="fa fa-trash-o"></i>删除</a>';
                    }
                }
            ];
            $("#trigger_list").datagrid({ columns: columns}).loadData(host_name + "rule/single?gettrigger=all&id=" + selectRue, "get");
        });
        //触发器定义
        function openDefineWin() {
            openModalWin("触发器定义", "triggerinfo.html?mode=1&identity=" + selectRue, Synchronization, 700, 500);
        }
        //编辑触发器
        function openModifyWin(value) {
            openModalWin("编辑触发器", "triggerinfo.html?mode=2&index=" + value + "&identity=" + selectRue, Synchronization, 700, 500);
        }
        //触发器删除
        function openDeleteWin(i, n, t, p, at, ac) {
            var delUrl = host_name + "rule/updatetrigger";
            var trigger = JSON.stringify({ index: i, name: n, testFunc: t, parameters: p, actionType: at, actionScript: ac });
            if (confirm("确定要删除选定的数据吗？")) {
                $.ajax({
                    url: delUrl,
                    type: "post",
                    data: JSON.stringify({ Id: selectRue, Trigger: trigger, Action: "delete" }),
                    success: function (data) {
                        Synchronization();
                    }
                });
            }
        }
        function ReturnHome() {
            window.open("triggerrule.html", "appIframe");
        }
        //同步
        function Synchronization() {
            $("#trigger_list").datagrid().refresh();
        }
    </script>
</head>
<body>
    <div class="container-fluid">
        <div class="row" style="margin-bottom:10px">
            <div class="col-md-2">
                <h4>报警策略——触发器</h4>
            </div>
            <div class="col-md-10">
                <div class="menu-container pull-right">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 table-responsive">
                <table id="trigger_list" class="table table-bordered table-hover"></table>
            </div>
        </div>
    </div>
</body>
</html>